<template>
  <div class="alarm-record">
    <el-table :data="tableData" border style="width: 100%; flex: 1">
      <el-table-column prop="alarmTypeName" label="报警类型" width="120" align="center" />
      <el-table-column prop="alarmContent" label="报警内容" header-align="center" min-width="200" />
      <el-table-column label="最大值" width="100" align="center">
        <template #default="scope">
          <span v-if="scope.row.maxValue">{{ scope.row.maxValue + scope.row.unitCode }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="alarmReason" label="报警原因" header-align="center" min-width="200" />
      <el-table-column prop="alarmResult" label="处置措施" header-align="center" min-width="200" />
      <el-table-column prop="disposalLevelName" label="处置情况" width="90" align="center" />
      <el-table-column prop="beginDate" label="开始时间" width="110" align="center" />
      <el-table-column prop="endDate" label="结束时间" width="110" align="center" />
      <el-table-column prop="keepTimeStr2" label="持续时长" width="120" align="center" />
    </el-table>
    <el-pagination
      class="pagination"
      v-model:current-page="searchParams.pageNumber"
      :page-size="searchParams.pageSize"
      :total="searchParams.total"
      layout="total, prev, pager, next"
      @current-change="handleCurrentChange"
    />
  </div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { getSensorAlarmList } from '@/api/alarm'

const props = defineProps({
  sensor: {
    type: Object as PropType<{
      cdCode: string
    }>,
    required: true
  }
})

const tableData = ref([])
const searchParams = ref({
  pageNumber: 1,
  pageSize: 20,
  total: 0,
  cdCode: props.sensor.cdCode
})

function handleCurrentChange(pageNumber: number) {
  searchParams.value.pageNumber = pageNumber
  getSensorAlarmListData()
}

async function getSensorAlarmListData() {
  const { data } = await getSensorAlarmList(searchParams.value)
  tableData.value = data.records
  searchParams.value.total = data.total
  searchParams.value.pageNumber = data.current
}

onMounted(async () => {
  getSensorAlarmListData()
})
</script>
<style lang="scss" scoped>
.alarm-record {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.disposition-situation {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  justify-content: center;
}
.pagination {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
}
</style>
